package cn.shengongying.admin.controller;

import cn.shengongying.bean.ResponseResult;
import cn.shengongying.enums.CacheKeyEnum;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

/**
 * author: RXK
 * date: 2022/2/10 星期四
 * desc:
 */
@Controller
@RequestMapping("/sys")
public class SysController extends BaseController {

    private final RedisTemplate<String, String> redisTemplate;

    public SysController(RedisTemplate<String, String> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @RequestMapping("/official/msg/index")
    public String officialMsgIndex() {
        return "/officialmsg/index";
    }

    @RequestMapping("/service/charge/index")
    public ModelAndView baseServiceChange(ModelAndView modelAndView) {
        String value = redisTemplate.opsForValue()
                .get(CacheKeyEnum.service_charge.getKey());
        modelAndView.addObject("last", value);
        modelAndView.setViewName("/sys/service_change");
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping("/save/service/charge")
    public ResponseResult<String> saveServiceCharge(Integer charge) {
        redisTemplate.opsForValue()
                .set(CacheKeyEnum.service_charge.getKey(), charge.toString());
        return ResponseResult.success();
    }


    @ResponseBody
    @RequestMapping("/file/save")
    public ResponseResult<String> saveFile(MultipartFile multipartFile) {
        String name = multipartFile.getName();
        long size = multipartFile.getSize();
        return ResponseResult.success();
    }


}
